
import 'package:app/routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/core_enum.dart';
import 'package:flutter_jpf_core/page/base_state_page.dart';
import 'package:flutter_jpf_core/util/colors_util.dart';
import 'package:flutter_jpf_core/util/data_util.dart';
import 'package:flutter_jpf_core/extension/map_extension.dart';
import 'package:flutter_jpf_core/widgets/jpftext.dart';
import 'package:flutter_jpf_core/widgets/widget_factory.dart';
import 'package:flutter_jpf_core/model/select_model.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_jpf_debug/log.dart';


//'/home':(BuildContext context) => HomePage()
//调用：Navigator.of(context).pushNamed("/home",arguments: {"title":""});
class HomePage  extends CommBasePage{

  @override
  CommBaseState getPageState() {
    return HomePageState();
  }

}
class HomePageState extends CommBaseState<HomePage> {


  String title = "首页";
  Map<String,dynamic> _serviceData;
  List<JPFRoute> _lstMenu = List();

  ///////////////生命周期//////////////////////
  //初始化参数
  @override
  void initBaseParams() {
    // TODO: implement initBaseParams
    _lstMenu = Routes.menus;
  }

  //初始化页面数据，父类Widget build(BuildContext context)延时之后
  @override
  void initPageData() {
    Map data = getPageArguments();
    if(!DataUtil.isMapEmpty(data)){
      if(data["title"] != null){
        setState(() {
          title = data.strValue("title");
        });
      }
    }
    queryServiceData();
  }


  ///////////////接口相关//////////////////////
  @override
  void queryServiceData({ServiceType type = ServiceType.Default, bool showAnimail = true}) {
    // TODO: implement queryServiceData
    //重置无数据组件
    setState(() {
      setNodataView(strMsg: "");
    });
    if(type == ServiceType.Default && showAnimail){
      //showProgressDialog(msg: "加载中...");
    }
  }


  ///////////////操作相关//////////////////////
  //提交数据
  void submitAction(){

  }


  ///////////////UI相关//////////////////////
  //页面UI
  @override
  Widget getViewsWidget() {
    hideProgressDialog();
    // TODO: implement getViewsWidget
    return Scaffold(
        appBar: WidgetFatory.createMyAppBar(title, context,hasLeftIcon: false),
        backgroundColor: ColorsUtil.view_background,
        body: _lstMenu.length<1?nodataView():Container(
          padding: EdgeInsets.only(left: 5,top: 10),
          child:  Wrap(
              runSpacing: 10,
              spacing: 10,
              children: _lstMenu.map((JPFRoute model) => listItemView(model)).toList()),
        )
    );
  }

  ///////////////get/set//////////////////////
  Widget listItemView(JPFRoute item){
    //SelectModel item = _lstMenu[index];
    return Container(color: ColorsUtil.white,
      child: GestureDetector(child: Container(height: 45,
        margin: EdgeInsets.only(left: 10,right: 10,top: 5,bottom: 5),
        constraints: BoxConstraints(minWidth: 60,maxWidth: ScreenUtil.screenWidth/3-30),
        decoration: BoxDecoration(color: ColorsUtil.view_background,borderRadius: BorderRadius.all(Radius.circular(5))),
        child: JPFText("${item.name}",alignment: Alignment.center,margin: EdgeInsets.only(left: 10),),),
      onTap: (){
        Navigator.of(context).pushNamed(item.path,arguments: {"title":item.name});
      },
      ));
  }


}